﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace EWMSWeb.ashx
{
    /// <summary>
    /// cjoOper 的摘要说明
    /// </summary>
    public class cjoOper : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string strResult = "";            
            if (context.Request["cjoid"] != null && context.Request["opettype"] !=null)
            {
                int cjoid = int.Parse(context.Request["cjoid"].ToString());
                strResult = UpdateCjo(cjoid,context.Request["opettype"]); ;
            }
            context.Response.Write(strResult);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public string UpdateCjo(int cjoid, string opertype)
        {
            string strresult = "0";
            DataLib.BLL.Cjo bll = new DataLib.BLL.Cjo();
            DataLib.Model.Cjo model = bll.GetModel(cjoid);

            if (model != null)
            {
                switch (opertype)
                {
                    case "loadstatus":
                        //撤销授权批复
                        model.status = 3;
                        break;
                    case "cjozfstatus":
                        //作废
                        model.status = -9;
                        break;
                    case "cjocxzfstatus":
                        //撤销作废
                        if (model.cjoadd.IndexOf("自送") >= 0)
                        {
                            model.status = 2;
                        }
                        else
                        {
                            model.status = 1;
                        }
                        break;
                    case "auth":
                        //授权
                        model.status = 4;
                        break;
                    case "authcancel":
                        //撤销授权
                        model.status = -4;
                        break;
                    default:
                        break;
                }


                if (bll.Update(model))
                {
                    strresult = model.status.ToString();
                }
                else
                {
                    strresult = "1";
                }

            }
            else
            {
                strresult = "0";
            }
            return strresult;
        }

      
    }
}